package com.lmx.lmx_intrefance.controller;

import cn.hutool.json.JSONUtil;
import com.lmx.lmx_intrefance.pojo.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lmx
 */
@RestController
@RequestMapping("/name")
@ResponseBody
public class NaceApiController {
    private String pre = "得到的名字是：";

    @GetMapping("")
    public String getName(@RequestParam String name) {
        return pre + name;
    }

    @PostMapping
    public String postName(@RequestParam String name) {
        return pre + name;
    }


    @PostMapping("namejson")
    public String postNameByJson(@RequestBody User user, HttpServletRequest request) {
//        String accesskey = "lmx";
//        String secretKey = "abcdefg";
//        String accessKey = request.getHeader("accessKey");
//        String noce = request.getHeader("noce");
//        String timestamp = request.getHeader("timestamp");
//        String sign = request.getHeader("sign");
//        String body=request.getHeader("body");
////        校验调用者是否有权限
////        1.查询数据库，调用接口用户是否存在
////        2.判断noce是否用过
//        if (noce != null) {
////            ToDO 从缓存中取出使用过noce，是否包含当前的noce，如果包含，抛异常
//
//        }
////        3.判断timestamp是否在5分钟之内
//        if (timestamp != null) {
//            long currentTimeMillis = System.currentTimeMillis() / 100000;
//            long timestampMIllis = Long.parseLong(timestamp);
//            long time=300000;
////             发送请求时间距离限制啊时间超过五分钟
//            if (currentTimeMillis - timestampMIllis>time){
//                throw new RuntimeException("调用接口间隔时间过长");
//            }
//
//        }
//
////        4.获取scrept进行加密计算
//        String serverSign = SecretUntil.getSign(body, secretKey);
//
//        if (!sign.equals(serverSign)) {
//            throw new RuntimeException("无权限");
//        }
        return pre + user.getName();
    }

}
